{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "408cde6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "      x    y\n",
      "0     1  562\n",
      "1   324  256\n",
      "2   543   26\n",
      "3    26  245\n",
      "4    54  546\n",
      "5   635  265\n",
      "6    45  256\n",
      "7   272  764\n",
      "8    65  876\n",
      "9   653  356\n",
      "10  631  145\n",
      "11  556  767\n",
      "12  765  245\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data = pd.read_csv('pandas_data.csv')\n",
    "print(type(data))\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "73a7d3f8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0       1\n",
      "1     324\n",
      "2     543\n",
      "3      26\n",
      "4      54\n",
      "5     635\n",
      "6      45\n",
      "7     272\n",
      "8      65\n",
      "9     653\n",
      "10    631\n",
      "11    556\n",
      "12    765\n",
      "Name: x, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "#获取x的值\n",
    "x = data.loc[:,'x']\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9e1c6a7a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0     562\n",
      "1     256\n",
      "2      26\n",
      "3     245\n",
      "4     546\n",
      "5     265\n",
      "6     256\n",
      "7     764\n",
      "8     876\n",
      "9     356\n",
      "10    145\n",
      "11    767\n",
      "12    245\n",
      "Name: y, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "#获取y的值\n",
    "y = data.loc[:,'y']\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3be20528",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0       1\n",
      "1     324\n",
      "3      26\n",
      "4      54\n",
      "5     635\n",
      "6      45\n",
      "7     272\n",
      "8      65\n",
      "9     653\n",
      "10    631\n",
      "11    556\n",
      "12    765\n",
      "Name: x, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# 当y>200的时候对应的x的值\n",
    "c = data.loc[:,'x'][y>50]\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3a868c5c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "[[  1 562]\n",
      " [324 256]\n",
      " [543  26]\n",
      " [ 26 245]\n",
      " [ 54 546]\n",
      " [635 265]\n",
      " [ 45 256]\n",
      " [272 764]\n",
      " [ 65 876]\n",
      " [653 356]\n",
      " [631 145]\n",
      " [556 767]\n",
      " [765 245]]\n"
     ]
    }
   ],
   "source": [
    "#将pandas读取到的数据转成 numpy的数组\n",
    "import numpy as np\n",
    "data_array = np.array(data)\n",
    "print(type(data_array))\n",
    "print(data_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8866388f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11</td>\n",
       "      <td>572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>334</td>\n",
       "      <td>266</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>553</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>36</td>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>64</td>\n",
       "      <td>556</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     x    y\n",
       "0   11  572\n",
       "1  334  266\n",
       "2  553   36\n",
       "3   36  255\n",
       "4   64  556"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每个数据加10\n",
    "data_new = data + 10\n",
    "#预览数据\n",
    "data_new.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "438f2425",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存数据\n",
    "data_new.to_csv('pandas_data_new.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e547a8f7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
